package org.com.coolfish.common.database.repository;


import java.math.BigDecimal;
import java.util.List;

import org.com.coolfish.common.database.entity.KuyuOrderFlow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface KuyuOrderFlowRepository extends JpaRepository<KuyuOrderFlow, Integer> {
	@Modifying
    @Query("UPDATE KuyuOrderFlow e SET e.type =2 ,e.addtime = NOW(),e.status=2,e.trade_type=3 ,e.money =:money WHERE e.cardid =:id")
	void changeOrderFlow(@Param("money") BigDecimal money,@Param("id") Integer id);
	
	@Modifying
    @Query("UPDATE KuyuOrderFlow e SET e.type =0 ,e.addtime = NOW() WHERE e.cardid =:id")
	void changeOrderType(@Param("id") Integer id);
	
	
	@Modifying
	@Query("UPDATE KuyuOrderFlow e SET e.type =0 ,e.addtime = NOW(),e.status=2,e.trade_type=4  WHERE e.cardid =:id")
	void changeStatusOfKuyuOrderFlow(@Param("id") Integer id);
	
	
	@Query("SELECT new KuyuOrderFlow(e.packageid,e.cardid,e.operatorid,e.trade_type,e.iccid) FROM KuyuOrderFlow e WHERE e.status=2")
	List<KuyuOrderFlow> fandOrderbyStatus();
}
